<template>
	<view class="container" style="height:100vh;">
		<u-navbar :is-fixed="true" :border-bottom="false"></u-navbar>
		<view class="pair-head">
			<image class="pair-head-face" :src="userInfo.avatar.file_path" mode="aspectFill" />
			<view class="pair-head-name">Hi，{{ userInfo.nickName }}</view>
		</view>
		<view class="pair-desc">珍惜每一个相遇的灵魂铭记每一刻难忘的瞬间。</view>
		<view class="pair-chunk">
			<view class="pair-chunk-item" :style="{ height: cartHeight + 'px' }">
				<view class="pair-chunk-card" @tap="chooseSingle" data-gender="2" :data-id="matchObject.girl ? matchObject.girl.user_id : -1">
					<view class="pair-chunk-card-photo" :class="{ fill: matchObject.girl }" >
						<image class="pair-chunk-card-photo-image" :src="matchObject.girl ? matchObject.girl.avatar : `${staticFileDomain}/static/image/background-pair-girl.png`" mode="aspectFill"></image>
					</view>
					<view class="pair-chunk-card-name" v-if="matchObject.girl">{{ matchObject.girl.nickName }}</view>
				</view>
				<view class="pair-chunk-sex pair-chunk-sex-girl" @tap="chooseSingle" data-gender="2" :data-id="matchObject.girl ? matchObject.girl.user_id : -1"><image class="pair-chunk-sex-image" src="@/static/images/matchmaker/icon-pair-girl.png" mode="aspectFit"></image></view>
			</view>
			<view class="pair-chunk-item" :style="{ height: cartHeight + 'px' }">
				<view class="pair-chunk-card" @tap="chooseSingle" data-gender="1" :data-id="matchObject.boy ? matchObject.boy.user_id : -1">
					<view class="pair-chunk-card-photo" :class="{ fill: matchObject.girl }" >
						<image class="pair-chunk-card-photo-image" :src="matchObject.boy ? matchObject.boy.avatar : `${staticFileDomain}/static/image/background-pair-boy.png`" mode="aspectFill"></image>
					</view>
					<view class="pair-chunk-card-name" v-if="matchObject.boy">{{ matchObject.boy.nickName }}</view>
				</view>
				<view class="pair-chunk-sex pair-chunk-sex-boy" @tap="chooseSingle" data-gender="2" :data-id="matchObject.girl ? matchObject.girl.user_id : -1"><image class="pair-chunk-sex-image" src="@/static/images/matchmaker/icon-pair-boy.png" mode="aspectFit"></image></view>
			</view>
		</view>
		<view class="pair-submit" @tap.stop="createGroup"><view class="pair-submit-text">牵线</view></view>
		<pair-popup-manager v-model="singlePopupShow" :gender="gender" @confirm="confirmPair" :defaultUserId="defaultUserId"></pair-popup-manager>
	</view>
</template>

<script>
import Tools from '@/utils/Tools.js';
import pairPopupManager from '../components/pair/pair-popup-manager.vue';
export default {
	components: { pairPopupManager },
	data() {
		return {
			matchObject: {
				girl: null,
				boy: null
			},

			gender: 1,
			defaultUserId: null,
			singlePopupShow: false,
			cartHeight: null
		};
	},
	onShow() {
		const systemInfo = uni.getSystemInfoSync();
		const cartHeight = systemInfo.windowHeight - systemInfo.statusBarHeight - 44 - uni.upx2px(88 + 2 + 34 + 13 + 30 + 80 + 66 + 80) - Tools.getSafeAreaBottomHeight();

		this.cartHeight = cartHeight;
		console.log(cartHeight);
	},
	methods: {
		chooseSingle(e) {
			this.gender = e.currentTarget.dataset.gender;
			this.defaultUserId = e.currentTarget.dataset.id;
			this.singlePopupShow = true;
		},
		confirmPair(data) {
			this.singlePopupShow = false;
			if (data) {
				if (this.gender == 1) {
					this.$set(this.matchObject, 'boy', data);
				} else {
					this.$set(this.matchObject, 'girl', data);
				}
			}
		},
		createGroup() {
			const { girl, boy } = this.matchObject;
			if (girl && boy) {
				this.$u.api.pullInGroup([girl.user_id, boy.user_id]).then(res => {
					this.redirectTo({
						url: '/pageChat/group/index?group_id=g_' + res.data.group_id
					});
				});
			}
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #fff;
}
.pair-head {
	margin-top: 2rpx;
	height: 88rpx;
	display: flex;
	align-items: flex-end;
	padding: 0 40rpx;
	.pair-head-face {
		height: 88rpx;
		width: 88rpx;
		border-radius: 44rpx;
		flex-shrink: 0;
	}
	.pair-head-name {
		display: flex;
		align-items: flex-end;
		margin-left: 16rpx;
		height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		line-height: 45rpx;
	}
}
.pair-desc {
	height: 34rpx;
	font-size: 24rpx;
	font-weight: 400;
	color: rgba(151, 151, 151, 1);
	display: flex;
	align-items: center;
	margin-top: 13rpx;
	padding: 0 40rpx;
}
.pair-chunk {
	padding: 0 40rpx;
	display: flex;
	justify-content: space-between;
	margin-top: 30rpx;
	.pair-chunk-item {
		width: 315rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		.pair-chunk-card {
			flex: 1;
			display: flex;
			flex-direction: column;

			.pair-chunk-card-photo {
				width: 315rpx;
				background: #fff;
				flex: 1;
				border-radius: 40rpx;
				&.fill {
					height: 518rpx !important ;
				}
				.pair-chunk-card-photo-image {
					height: 100%;
					width: 100%;
					border-radius: 40rpx;
				}
			}
			.pair-chunk-card-name {
				width: 315rpx;
				height: 76rpx;
				background: rgba(248, 248, 248, 1);
				box-shadow: 0px 4rpx 6rpx 0rpx rgba(0, 0, 0, 0.12);
				border-radius: 38rpx;
				margin-top: 46rpx;
				padding: 0 19rpx;
				flex-shrink: 0;
				display: flex;
				justify-content: center;
				align-items: center;

				font-size: 32rpx;
				font-weight: 500;
				color: rgba(196, 198, 201, 1);
				flex-shrink: 0;
			}
		}
		.pair-chunk-sex {
			width: 114rpx;
			height: 114rpx;
			box-shadow: 0px 4rpx 6rpx 0px rgba(0, 0, 0, 0.12);
			border-radius: 57rpx;
			margin-top: 54rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-shrink: 0;

			.pair-chunk-sex-image {
				height: 45rpx;
				width: 45rpx;
			}
			&-girl {
				background: rgba(248, 89, 98, 0.1);
			}
			&-boy {
				background: rgba(248, 248, 248, 1);
			}
		}
	}
}
.pair-submit {
	width: 400rpx;
	height: 80rpx;
	position: relative;
	margin: 66rpx auto 0;
	&::before {
		content: '';
		position: absolute;
		width: 331rpx;
		height: 70rpx;
		background: linear-gradient(180deg, rgba(237, 79, 93, 1) 0%, rgba(251, 122, 142, 1) 100%);
		border-radius: 35rpx;
		opacity: 0.29;
		filter: blur(3rpx);
		top: 24rpx;
		left: 50%;
		transform: translateX(-50%);
	}
	.pair-submit-text {
		width: 400rpx;
		height: 80rpx;
		background: linear-gradient(180deg, rgba(237, 79, 93, 1) 0%, rgba(251, 122, 142, 1) 100%);
		border-radius: 40px;
		display: flex;
		justify-content: center;
		align-items: center;

		font-size: 32rpx;
		font-weight: 400;
		color: rgba(255, 255, 255, 1);
	}
}
</style>
